<template>
  <div id="app">
    <div class="container">
      <div class="close"><span class="iconfont iconicon-test"></span></div>
      <div class="logo"><span class="iconfont iconnew"></span></div>
      <div class="inputs">
        <myinput
          v-model="user.username"
          placeholder="请输入用户名/手机号"
          :rules="/^1\d{4}$|^1[35789]\d{9}$/"
          msg="请输入5位或者11位的手机号"
        >
        </myinput>
        <myinput
          v-model="user.nickname"
          placeholder="昵称"
          :rules="/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/"
          msg="请输入昵称"
        >
        </myinput>
        <myinput
          class="input"
          type="password"
          v-model="user.password"
          placeholder="请输入密码"
          :rules="/^.{3,16}$/"
          msg="请输入3-16位的密码"
        >
        </myinput>
        <p class="tips">
          已有账号？
          <a href="#/login" class>去登陆</a>
        </p>
        <!-- mybutton点击事件监听 -->
        <!-- 传入自定义样式名 -->
        <mybutton @click="register" type="primary">注册</mybutton>
        <!-- <van-button type="primary">主要按钮</van-button> -->
      </div>
    </div>
  </div>
</template>

<script>
// 引入封装的button组件
import mybutton from "@/components/mybutton";

// 引入封装的input框组件
import myinput from "@/components/myinput";

// // 引入axios
import { register } from "@/api/user.js";

export default {
  data() {
    return {
      user: {
        username: "",
        nickname: "",
        password: "",
      },
    };
  },
  components: {
    mybutton,
    myinput,
  },
  methods: {
    async register() {
      let res = await register(this.user);
      console.log(res);
      if (res.data.message == "注册成功") {
        this.$toast.success("注册成功");
        this.$router.push({ name: "login" });
      } else if (res.data.statusCode == 400) {
        this.$toast.fail(res.data.message);
      }
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  padding: 20px;
}

.close {
  span {
    font-size: 27 / 360 * 100vw;
  }
}

.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: 126 / 360 * 100vw;
    color: #d81e06;
  }
}

.inputs {
  input {
    margin-bottom: 20px;
  }
}

.tips {
  text-align: right;
  margin-bottom: 20px;

  a {
    color: #3385ff;
  }
}
</style>